home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso / shareware / intuition / reqtools_2.1e / glue / gcc / gcc_glue.lha / demo.c next >
C/C++ Source or Header  |  1993-02-27  |  16KB  |  521 lines

  1. /*********************************
  2. *                                *
  3. *  reqtools.library (V38)        *
  4. *                                *
  5. *  Release 2.0                   *
  6. *                                *
  7. *  (c) 1991-1993 Nico François   *
  8. *                                *
  9. *  demo.c                        *
  10. *                                *
  11. *  This source is public domain  *
  12. *  in all respects.              *
  13. *                                *
  14. *********************************/
  15.  
  16. /*********************************
  17. *                                *
  18. *  GCC demo                      *
  19. *                                *
  20. *  (c) 1993 Marc Duponcheel      *
  21. *                                *
  22. *********************************/
  23.  
  24. #include <exec/types.h>
  25. #include <exec/memory.h>
  26. #include <exec/execbase.h>
  27. #include <libraries/dos.h>
  28. #include <intuition/intuition.h>
  29.  
  30. #ifndef __GCC__
  31. #include <proto/exec.h>
  32. #include <proto/dos.h>
  33. #else
  34. #include <clib/exec_protos.h>
  35. #include <dos/exall.h>
  36. #include <clib/dos_protos.h>
  37. #endif
  38. #include <stdio.h>
  39.  
  40. #include <libraries/reqtools.h>
  41. #ifndef __GCC__
  42. #include <proto/reqtools.h>
  43. #else
  44. #include <clib/reqtools_protos.h>
  45.     #ifdef DEMO_INLINE
  46. #define static
  47. #define __inline
  48. /* should become <inline/reqtools.h> once you installed it there */
  49. #include "inline/reqtools.h"
  50.     #endif
  51. #endif
  52.  
  53. extern struct ExecBase *SysBase;
  54. struct ReqToolsBase *ReqToolsBase;
  55.  
  56. #define REG register
  57.  
  58. #ifdef DOHOOKS
  59. #ifndef __GCC__
  60. /* Callback functions
  61.     Define DOHOOKS when you compile to activate these filter functions */
  62.  
  63. BOOL __asm __saveds file_filterfunc (
  64.     REG __a0 struct Hook *, REG __a2 struct rtFileRequester *,
  65.     REG __a1 struct FileInfoBlock *
  66.     );
  67. BOOL __asm __saveds font_filterfunc (
  68.     REG __a0 struct Hook *, REG __a2 struct rtFontRequester *,
  69.     REG __a1 struct TextAttr *
  70.     );
  71. BOOL __asm __saveds vol_filterfunc (
  72.     REG __a0 struct Hook *, REG __a2 struct rtFileRequester *,
  73.     REG __a1 struct rtVolumeEntry *
  74.     );
  75. #else
  76. BOOL file_filterfunc ();
  77. BOOL font_filterfunc ();
  78. BOOL vol_filterfunc ();
  79. #endif __GCC__
  80. #endif DOHOOKS
  81.  
  82. ULONG undertag[] = { RT_Underscore, '_', TAG_END };
  83.  
  84. void myputs (char *str)
  85. {
  86.     Write (Output(), str, strlen(str));
  87. }
  88.  
  89. #ifndef __GCC__
  90. _main()
  91. #else
  92. int    main()
  93. #endif
  94. {
  95.     struct rtFileRequester *filereq;
  96.     struct rtFontRequester *fontreq;
  97.     struct rtScreenModeRequester *scrmodereq;
  98.     struct rtFileList *flist, *tempflist;
  99. #ifdef DOHOOKS
  100.     struct Hook filterhook, font_filterhook, vol_filterhook;
  101. #endif
  102.     char buffer[128], filename[34];
  103.     long longnum, ret, color;
  104.  
  105.     if (!(ReqToolsBase = (struct ReqToolsBase *)
  106.                                           OpenLibrary (REQTOOLSNAME, REQTOOLSVERSION))) {
  107.         myputs ("You need reqtools.library V38 or higher!\n"
  108.                   "Please install it in your Libs: drirectory.\n");
  109.         exit (0);
  110.         }
  111.  
  112.     rtEZRequest ("ReqTools 2.0 Demo\n"
  113.                  "~~~~~~~~~~~~~~~~~\n"
  114.                      "'reqtools.library' offers several\n"
  115.                      "different types of requesters:",
  116.                      "Let's see them", NULL, NULL);
  117.  
  118.     rtEZRequest ("NUMBER 1:\nThe larch :-)", "Be serious!", NULL, NULL);
  119.  
  120.     rtEZRequest ("NUMBER 1:\nString requester\nfunction: rtGetString()",
  121.                      "Show me", NULL, NULL);
  122.  
  123.     strcpy (buffer, "A bit of text");
  124.     if (!rtGetString (buffer, 127, "Enter anything:", NULL, TAG_END))
  125.         rtEZRequest ("You entered nothing :-(", "I'm sorry", NULL, NULL);
  126.     else
  127.         rtEZRequest ("You entered this string:\n'%s'.",
  128.                          "So I did", NULL, NULL, buffer);
  129.  
  130.     ret = rtGetString (buffer, 127, "Enter anything:", NULL,
  131.                              RTGS_GadFmt, " _Ok |New _2.0 feature!|_Cancel",
  132.                              RTGS_TextFmt,
  133.                                  "These are two new features of ReqTools 2.0:\n"
  134.                                   "Text above the entry gadget and more than\n"
  135.                                   "one response gadget.",
  136.                      TAG_MORE, undertag);
  137.     if (ret == 2)
  138.         rtEZRequest ("Yep, this is a new\nReqTools 2.0 feature!",
  139.                          "Oh boy!", NULL, NULL);
  140.  
  141.     ret = rtGetString (buffer, 127, "Enter anything:", NULL,
  142.                              RTGS_GadFmt, " _Ok |_Abort|_Cancel",
  143.                              RTGS_TextFmt,
  144.                                  "New is also the ability to switch off the\n"
  145.                                   "backfill pattern.  You can also center the\n"
  146.                                   "text above the entry gadget.\n"
  147.                                   "These new features are also available in\n"
  148.                                   "the rtGetLong() requester.",
  149.                              RTGS_BackFill, FALSE,
  150.                              RTGS_Flags, GSREQF_CENTERTEXT|GSREQF_HIGHLIGHTTEXT,
  151.                              TAG_MORE, undertag);
  152.     if (ret == 2)
  153.         rtEZRequest ("What!! You pressed abort!?!\nYou must be joking :-)",
  154.                          "Ok, Continue", NULL, NULL);
  155.                          
  156.  
  157.     rtEZRequest ("NUMBER 2:\nNumber requester\nfunction: rtGetLong()",
  158.                      "Show me", NULL, NULL);
  159.  
  160.     if (!rtGetLong (&longnum, "Enter a number:", NULL,
  161.                          RTGL_ShowDefault, FALSE,
  162.                          RTGL_Min, 0, RTGL_Max, 666,TAG_END))
  163.         rtEZRequest ("You entered nothing :-(",
  164.                          "I'm sorry", NULL, NULL);
  165.     else
  166.         rtEZRequest ("The number you entered was:\n%ld%s",
  167.                          "So it was", NULL, NULL, longnum,
  168.                             (longnum == 666) ? " (you devil! :)" : "");
  169.  
  170.     rtEZRequest ("NUMBER 3:\nMessage requester, the requester\n"
  171.                      "you've been using all the time!\nfunction: rtEZRequest()",
  172.                      "Show me more", NULL, NULL);
  173.  
  174.     rtEZRequest ("Simplest usage: some body text and\na single centered gadget.",
  175.                      "Got it", NULL, NULL);
  176.  
  177.     while (!rtEZRequest ("You can also use two gadgets to\n"
  178.                                 "ask the user something.\n"
  179.                                 "Do you understand?", "Of course|Not really",
  180.                                 NULL, NULL))
  181.         rtEZRequest ("You are not one of the brightest are you?\n"
  182.                          "We'll try again...",
  183.                          "Ok", NULL, NULL);
  184.  
  185.     rtEZRequest ("Great, we'll continue then.", "Fine", NULL, NULL);
  186.  
  187.     switch (rtEZRequest ("You can also put up a requester with\n"
  188.                                 "three choices.\n"
  189.                                 "How do you like the demo so far ?",
  190.                                 "Great|So so|Rubbish", NULL, NULL)) {
  191.         case FALSE:
  192.             rtEZRequest ("Too bad, I really hoped you\nwould like it better.",
  193.                              "So what", NULL, NULL);
  194.             break;
  195.         case TRUE:
  196.             rtEZRequest ("I'm glad you like it so much.", "Fine", NULL, NULL);
  197.             break;
  198.         case 2:
  199.             rtEZRequest ("Maybe if you run the demo again\n"
  200.                              "you'll REALLY like it.",
  201.                              "Perhaps", NULL, NULL);
  202.             break;
  203.         }
  204.  
  205.     ret = rtEZRequestTags ("The number of responses is not limited to three\n"
  206.                                   "as you can see.  The gadgets are labeled with\n"    
  207.                                   "the return code from rtEZRequest().\n"
  208.                                   "Pressing Return will choose 4, note that\n"
  209.                                   "4's button text is printed in boldface.",
  210.                                   "1|2|3|4|5|0", NULL, NULL,
  211.                                   RTEZ_DefaultResponse, 4, TAG_END);
  212.     rtEZRequest ("You picked '%ld'.", "How true", NULL, NULL, ret);
  213.  
  214.     rtEZRequestTags ("New for Release 2.0 of ReqTools (V38) is\n"
  215.                           "the possibility to define characters in the\n"
  216.                           "buttons as keyboard shortcuts.\n"
  217.                           "As you can see these characters are underlined.\n"
  218.                           "Pressing shift while still holding down the key\n"
  219.                           "will cancel the shortcut.\n"
  220.                           "Note that in other requesters a string gadget may\n"
  221.                           "be active.  To use the keyboard shortcuts there\n"
  222.                           "you have to keep the Right Amiga key pressed down.",
  223.                           "_Great|_Fantastic|_Swell|Oh _Boy",
  224.                           NULL, NULL,
  225.                           RT_Underscore, '_', TAG_END);
  226.  
  227.     rtEZRequest (
  228.         "You may also use C-style formatting codes in the body text.\n"
  229.         "Like this:\n\n"
  230.         "'The number %%ld is written %%s.' will give:\n\n"
  231.         "The number %ld is written %s.\n\n"
  232.         "if you also pass '5' and '\"five\"' to rtEZRequest().",
  233.         "_Proceed", NULL, (struct TagItem *)&undertag, 5, "five");
  234.  
  235.     if (rtEZRequestTags ("It is also possible to pass extra IDCMP flags\n"
  236.                                "that will satisfy rtEZRequest(). This requester\n"
  237.                                "has had DISKINSERTED passed to it.\n"
  238.                                "(Try inserting a disk).",
  239.                                "_Continue", NULL, NULL,
  240.                                RT_IDCMPFlags, DISKINSERTED,
  241.                                 RT_Underscore, '_', TAG_END)
  242.                                & DISKINSERTED)
  243.         rtEZRequest ("You inserted a disk.", "I did", NULL, NULL);
  244.     else
  245.         rtEZRequest ("You used the 'Continue' gadget\n"
  246.                          "to satisfy the requester.", "I did", NULL, NULL);
  247.  
  248.     rtEZRequestTags ("Finally, it is possible to specify the position\n"
  249.                           "of the requester.\n"
  250.                           "E.g. at the top left of the screen, like this.\n"
  251.                           "This works for all requesters, not just rtEZRequest()!",
  252.                           "_Amazing", NU